<?php
/*
KAP 0.3
composant de production de l'affichage

// cette implémentation repose sur la librairie noyau kap_arraypath
et sur le composant templatefeeder


file version 2004-12-09 16:18:37
*/

class kap_pageManager extends kap_core_component {
/*----------------------------------------------------------------------------------------------
                                                                                      proprietes
----------------------------------------------------------------------------------------------*/
	var $default_parameters=array(
		'path'=>'xhtml/' // chemin des templates
	);
	var $template; // template a utiliser
	/*var $pageData=array(
		'head'=>array(),
		'body'=>array(),
	);*/
	var $data;
/*----------------------------------------------------------------------------------------------
                                                                                    constructeur
----------------------------------------------------------------------------------------------*/
	function kap_pageManager(& $controller) {
		// appel du constructeur parent
		$const=get_parent_class($this);
		parent::$const($controller);
		// librairies
		//kapNeedClass('arraypath');
		$this->data=& kapNeedCoreObject('arraypath');
		//$this->data->loadData(array('head'=>'','body'=>''));
	}
/*----------------------------------------------------------------------------------------------
                                                                              methodes publiques
----------------------------------------------------------------------------------------------*/
	// indique le template a utiliser
	function setTemplate($template, $path=NULL) {
		if ($path!==NULL and is_file($path.$template)) $template=$path.$template;
		if (is_file($this->parameters['path'].$template)) $template=$this->parameters['path'].$template;
		$this->template=$template;
	}
	
	function setTitle($title) {
		//$this->pageData['head']['title']=$title;
		return $this->data->set('/head/title',$title);
	}
	// insère un contenu à l'emplacement indiqué
	function insert($content,$path='/body',$id=NULL) {
		$ref=$this->data->get($path);
		$done=false;
		//echo affvar($refs);
		//$ref=&$refs[0];
		//echo $path.' : '.affvar($ref).' => '.affvar($content);
		switch (gettype($ref)) {
			case "string":
				$done=$this->data->set($path,$ref.$content);
				//$ref.=$content;
				break;
			case "array":
				$ref[$id]=$content;
				$done=$this->data->set($path,$ref);
				break;
			default:
				$done=$this->data->set($path,$content);
				break;
			//default: return false;
		}
		//echo affvar($this->data->get('/'));
		kapLog("kap_pageManager->insert: inserted ".strlen($content)." chars into $path");
		return $done;
	}
	
	function set($content,$path='/body') {
		/*$ref=& $this->findOrMakeBlock($path);
		$ref=$content;*/
		return $this->data->set($path,$content);
	}
	
	function delete($path) {
		return $this->data->set($path,NULL);
	}
	
	function & getPage() {
		return kapTemplateFeed($this->template,$this->data->get());
	}
/*----------------------------------------------------------------------------------------------
                                                                              methodes privees
----------------------------------------------------------------------------------------------*/

}
?>
